package FileClient;

import javax.swing.JLabel;

import GUI.GUI;
import GUI.ImagePanel;


/**
 * En tråd som kommer polla en PictureQueue efter fler bilder att skicka till GUI.
 * @author dt08dl4
 *
 */
public class PictureUpdateThread extends Thread {
	private PictureQueue queue;
	private ImagePanel imagePanel;
	private JLabel delayLabel;	
	
	public PictureUpdateThread(GUI gui, PictureQueue queue, int id){
		this.queue = queue;
		
		if(id == 1){
			imagePanel = gui.getImagePanel1();
			delayLabel = gui.getDelayLabel1();
		}else if(id == 2){
			imagePanel = gui.getImagePanel2();
			delayLabel = gui.getDelayLabel2();
		}else{
			System.out.println("WRONG IMAGEPANEL INPUT!!!");
		}
		
	}
	
	
	
	public void run(){
		while(true){
			Picture nextPic = queue.getNextPic();
			if(nextPic != null){
//				delayLabel.setText("Delay: " + nextPic.getDelay() + " ms");
				delayLabel.setText("" + nextPic.getDelay());
				imagePanel.refresh(nextPic.getData());
			}

		}
	}

}
